<template>
  <div class>
    <div class="square_header flex align_center">
      <div
        class="square_header_item"
        :class="active == index ? 'underline ' : ''"
        v-for="(item,index) in activity"
        :key="index"
        @click="checkItem(index)"
      >
        <span
          :class="active == index ? 'title1 color1 zIndex fontBold ' : 'default'"
        >{{ item.name }}</span>
      </div>
    </div>
    <van-swipe
      class="my-swipe"
      :autoplay="3000"
      indicator-color="white"
    >
      <van-swipe-item
        v-for="(item,index) in bannerList"
        :key="index"
        lazy-render
        @click="url(item)"
      >
        <img :src="item.tpic">
      </van-swipe-item>
    </van-swipe>
    <div class="home">
      <component :is="active == 0 ? TabAcivity : TabCurriculum" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { getBanner } from '@/api/index'
import TabAcivity from './tabAcivity.vue'
import TabCurriculum from './tabCurriculum.vue'
import { useRouter, useRoute } from 'vue-router'
const router = useRouter()
const route = useRoute()
const bannerList: any = ref([])
const active: any = ref(route.query.f || 0)
const activity: any = ref([
  {
    name: '活动'
  },
  {
    name: '课程'
  }
])

const checkItem = (index: any) => {
  active.value = index
  router.replace({
    path: '/find',
    query: { f: index }
  })
}

const url = async (item: any) => {
  if (item.href) {
    window.location.href = item.href
  }
}

const banner = async () => {
  bannerList.value = await getBanner({ type: 4 })
}

banner()

</script>

<style lang="less" scoped>
.home {
  margin: 0 15px;
  .request-btn {
    font-size: 16px;
    border: none;
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    width: 149px;
    height: 44px;
    background: #ff7a1f;
    box-shadow: 0px 2px 10px 0px rgba(238, 111, 42, 0.5);
    border-radius: 5px;
  }
  .onSearch {
    border-radius: 5px;
    margin-bottom: 20px;
    .label_icon {
      overflow: hidden;
      display: flex;
      align-items: center;
      .icon {
        width: 34px;
        height: 34px;
        object-fit: cover;
        margin-right: 14px;
      }
      span {
        margin: 0 14px 0 0;
        color: #d8d8d8;
      }
    }

    .van-field__left-icon {
      display: none;
    }
  }
}

  .my-swipe {
    width: 350px;
    height: 146px;
    background: #ff7a1f;
    box-shadow: 0px 2px 10px 0px rgba(238, 150, 103, 0.5);
    border-radius: 5px;
    margin:10px auto 20px;
    img {
      width: 100%;
      height: 146px;
      object-fit: cover;
    }
  }

.square_header {
  width: 96%;
  height: 52px;
  margin-top: 10px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: #f7f7f7;
  padding-left: 15px;
  .square_header_item {
    margin-right: 29px;
    .default {
      font-size: 19px;
      font-weight: bold;
      color: #454757;
    }
  }
}

.square_header2 {
  // margin-top: 22px;
  .square_header_item2 {
    margin-right: 32px;
    .default2 {
      font-size: 14px;
      font-weight: bold;
      color: #454757;
    }
  }
}
@media (min-width: 750px) {
  .home {
  margin: 0 15px;
  .request-btn {
    font-size: 16px;
    border: none;
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    width: 149px;
    height: 44px;
    background: #ff7a1f;
    box-shadow: 0px 2px 10px 0px rgba(238, 111, 42, 0.5);
    border-radius: 5px;
  }
  .onSearch {
    border-radius: 5px;
    margin-bottom: 20px;
    .label_icon {
      overflow: hidden;
      display: flex;
      align-items: center;
      .icon {
        width: 34px;
        height: 34px;
        object-fit: cover;
        margin-right: 14px;
      }
      span {
        margin: 0 14px 0 0;
        color: #d8d8d8;
      }
    }

    .van-field__left-icon {
      display: none;
    }
  }
}

  .my-swipe {
    width: 350px;
    height: 146px;
    background: #ff7a1f;
    box-shadow: 0px 2px 10px 0px rgba(238, 150, 103, 0.5);
    border-radius: 5px;
    margin:10px auto 20px;
    img {
      width: 100%;
      height: 146px;
      object-fit: cover;
    }
  }

.square_header {
  width: 96%;
  height: 52px;
  margin-top: 10px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: #f7f7f7;
  padding-left: 15px;
  .square_header_item {
    margin-right: 29px;
    .default {
      font-size: 19px;
      font-weight: bold;
      color: #454757;
    }
  }
}

.square_header2 {
  // margin-top: 22px;
  .square_header_item2 {
    margin-right: 32px;
    .default2 {
      font-size: 14px;
      font-weight: bold;
      color: #454757;
    }
  }
}
}
</style>
